import { Users } from "../entity/User";
import { getManager, Repository } from "typeorm";

export default class UserService {
  constructor(){

  }
  static async updateUser(id: number) {
    // 找到当前的数据
    const userRepository = getManager().getRepository(Users)
    let userToUpdate = await userRepository.findOne(id);
    userToUpdate!.password = "1234";
    // as 强制转换
    userRepository.save(userToUpdate as Users);
    
  }
  static async userList(id: number) {
    // 查询的操作
    // 获取实体类的API管理器
    // typeorm : 1. 实体类 2. api
    // find Count数量
    const userRepository = getManager().getRepository(Users)
    const res = await userRepository.findAndCount();
    // const res = await userRepository.findAndCount({
    //   where: {
    //     id,
    //   },
    // });
    return res;
  }
}
